package cn.ml.gaoJi.jiHe.list;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class LikedListDemo {
    public static void main(String[] args) {
        NewsTitle title1 = new NewsTitle(1,"1-北京晴天了1","admid");
        NewsTitle title2 = new NewsTitle(1,"2-北京晴天了2","admid");
        NewsTitle title3 = new NewsTitle(1,"3-北京晴天了3","admid");
        NewsTitle title4 = new NewsTitle(1,"4-北京晴天了4","admid");
        NewsTitle title5 = new NewsTitle(1,"5-北京晴天了5","admid");
        NewsTitle title6 = new NewsTitle(1,"6-北京晴天了6","admid");
        NewsTitle title7 = new NewsTitle(1,"7-北京晴天了7","admid");

        List list2 = new LinkedList();//list2只能使用list2方法，不能使用LinkList独有方法
        LinkedList list = new LinkedList();
        list.add(title1);
        list.add(title2);
        list.add(title3);
        list.add(1,title4);
        list.addFirst(title5);
        list.addLast(title6);
        list.add(title7);//addLast()在此方法前所以title6在title7前
        list.removeFirst();
        list.removeLast();
        System.out.println(list.size());
        //遍历新闻标题
        System.out.println("11----for循环---------------------");
        for (int i=0;i<list.size();i++){
            NewsTitle title = (NewsTitle) list.get(i);
            System.out.println(title.getTitle()+title.getAuthor());
        }
        System.out.println("222222----增强型for--------------------");
        for (Object s:list){
            NewsTitle title = (NewsTitle) s;
            System.out.println(title.getTitle()+title.getAuthor());
        }
        System.out.println("33333----iterator迭代器--------------------");
        Iterator itor = list.iterator();
        while (itor.hasNext()){
            NewsTitle title = (NewsTitle) itor.next();
            System.out.println(title.getTitle()+title.getAuthor());
        }

    }
}
